#!/bin/bash

echo "=== 本地服务安装脚本 ==="
echo "此脚本将安装本地Redis和RabbitMQ服务"
echo ""

# 检查是否安装了Homebrew
if ! command -v brew &> /dev/null; then
    echo "错误：未安装Homebrew，请先安装Homebrew"
    echo "安装命令：/bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
    exit 1
fi

echo "1. 安装Redis..."
brew install redis

echo "2. 启动Redis服务..."
brew services start redis

echo "3. 安装RabbitMQ..."
brew install rabbitmq

echo "4. 启动RabbitMQ服务..."
brew services start rabbitmq

echo "5. 启用RabbitMQ管理插件..."
/usr/local/sbin/rabbitmq-plugins enable rabbitmq_management

echo ""
echo "=== 安装完成 ==="
echo ""
echo "Redis服务："
echo "- 端口：6379"
echo "- 管理：redis-cli"
echo "- 状态：brew services list | grep redis"
echo ""
echo "RabbitMQ服务："
echo "- 端口：5672 (AMQP), 15672 (管理界面)"
echo "- 管理界面：http://localhost:15672"
echo "- 默认用户名/密码：guest/guest"
echo "- 状态：brew services list | grep rabbitmq"
echo ""
echo "6. 验证服务状态..."
echo "Redis状态："
brew services list | grep redis
echo ""
echo "RabbitMQ状态："
brew services list | grep rabbitmq
echo ""
echo "7. 测试连接..."
echo "测试Redis连接："
redis-cli ping
echo ""
echo "测试RabbitMQ连接："
nc -zv localhost 5672
echo ""
echo "=== 安装完成！现在可以使用本地服务进行开发 ===" 